package com.bulletelc.apollopre.module.welcome;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.bulletelc.apollopre.MyApplication;
import com.bulletelc.apollopre.R;
import com.bulletelc.apollopre.constants.SPKey;
import com.bulletelc.apollopre.framework.BaseActivity;
import com.bulletelc.apollopre.module.guide.GuideActivity;
import com.bulletelc.apollopre.module.main.MainActivity;
import com.bulletelc.apollopre.utils.SharedPreferencesUtil;

/**
 * author: lhl
 * time  : 2017/10/19
 * desc  : 欢迎页面home
 */

public class WelcomeActivity extends BaseActivity {

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    startActivity();
                    break;
            }
        }
    };

    @Override
    public int getLayoutRes() {
        return R.layout.welcome_activity;
    }

    @Override
    public void assignViews() {

    }

    @Override
    public void setListener() {

    }

    @Override
    public void initData(Bundle savedInstanceState) {
        Message message = handler.obtainMessage(0);
        handler.sendMessageDelayed(message, 1000);//1000毫秒后跳转界面
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);//防止内存溢出
    }

    @Override
    protected void setStatusBar() {

    }

    private void startActivity() {
        // 是否第一次安装，默认为false
        boolean isFirstInstall = SharedPreferencesUtil.getBoolean(MyApplication.getInstance(), SPKey.SP_FIRST_INSTALL);
        if (!isFirstInstall) {
            Intent intentGuide = new Intent(WelcomeActivity.this, GuideActivity.class);
            startActivity(intentGuide);
        } else {
            Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
            startActivity(intent);
        }
        finish();
    }
}
